﻿using Autofac;
using PMS.Core.Configuration;
using PMS.Core.Infrastructure;
using PMS.Core.Infrastructure.DependencyManagement;
using PMS.Web.Factories.Customers;
using PMS.Web.Factories.ExternalAuthentication;
using PMS.Web.Factories.NaviMenus;
using PMS.Web.Factories.ScheduleTasks;
using PMS.Web.Factories.Stores;
using PMS.Web.Factories.SystemModules;

namespace PMS.Web.Infrastructure
{
    /// <summary>
    /// Dependency registrar
    /// </summary>
    public class DependencyRegistrar : IDependencyRegistrar
    {
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, PMSConfig config)
        {
            //common factories

            //webpage factories
            builder.RegisterType<CustomerModelFactory>().As<ICustomerModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType<AclSupportedModelFactory>().As<IAclSupportedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType<StoreMappingSupportedModelFactory>().As<IStoreMappingSupportedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType<ExternalAuthenticationModelFactory>().As<IExternalAuthenticationModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType<SystemModuleModleFactory>().As<ISystemModuleModleFactory>().InstancePerLifetimeScope();
            builder.RegisterType<ScheduleTaskFactory>().As<IScheduleTaskFactory>().InstancePerLifetimeScope();
            builder.RegisterType<NaviMenuModelFactory>().As<INaviMenuModelFactory>().InstancePerLifetimeScope();

        }

        /// <summary>
        /// Gets order of this dependency registrar implementation
        /// </summary>
        public int Order => 2;
    }
}
